package Q718;

/**
 * 最长重读子数组
 * https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/
 *
 * @author 23737
 * @time 2021.11.27
 */
public class Test {
    public static void main(String[] args) {
        System.out.println(new Solution().findLength(new int[]{0,1,1,1,1}, new int[]{1,0,1,0,1}));
    }
}

/**
 * dp
 */
class Solution {
    public int findLength(int[] nums1, int[] nums2) {
        //define
        int[][] dp = new int[nums1.length + 1][nums2.length + 1];
        int result = 0;

        //dp
        for (int i = 1; i <= nums1.length; i++) {
            for (int j = 1; j <= nums2.length; j++) {
                if (nums1[i - 1] == nums2[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    result = Math.max(dp[i][j],result);
                }
            }
        }
        return result;
    }
}
